{% extends 'myadmin/base.html' %}
{% block main_body %}
<style>
    .detail-card {
        background: #fff;
        border-radius: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        padding: 20px;
        margin-bottom: 20px;
    }
    .info-row {
        display: flex;
        flex-wrap: wrap;
        margin: 10px 0;
        border-bottom: 1px dashed #eee;
        padding-bottom: 10px;
    }
    .info-label {
        flex: 0 0 160px;
        font-weight: 600;
        color: #666;
    }
    .info-value {
        flex: 1;
    }
    .table-box {
        overflow-x: auto;
        margin: 10px 0;
    }
    .dataTable {
        min-width: 800px;
    }
    .section-title {
        font-size: 18px;
        font-weight: 600;
        color: #333;
        margin-bottom: 15px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .btn-group {
        margin-top: 20px;
        text-align: center;
    }
</style>

<section class="content-header">
    <h1>食谱管理 <small>食谱详情</small></h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i> 首页</a></li>
        <li><a href="#">食谱管理</a></li>
        <li class="active">食谱详情</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- 食谱基本信息 -->
            <div class="detail-card">
                <div class="section-title">
                    <i class="fa fa-cutlery"></i> 食谱基本信息
                </div>
                <div class="info-row">
                    <div class="info-label">食谱ID：</div>
                    <div class="info-value">{{ recipe.recipe_id }}</div>
                </div>
                <div class="info-row">
                    <div class="info-label">食谱名称：</div>
                    <div class="info-value">{{ recipe.recipe_name }}</div>
                </div>
                <div class="info-row">
                    <div class="info-label">准备时间：</div>
                    <div class="info-value">{{ recipe.prep_time|default:'-' }} 分钟</div>
                </div>
                <div class="info-row">
                    <div class="info-label">烹饪时间：</div>
                    <div class="info-value">{{ recipe.cook_time|default:'-' }} 分钟</div>
                </div>
                <div class="info-row">
                    <div class="info-label">总热量：</div>
                    <div class="info-value">{{ recipe.total_calories|default:'-' }} 大卡</div>
                </div>
                <div class="info-row">
                    <div class="info-label">慢性病适用：</div>
                    <div class="info-value">{% if recipe.is_suitable_for_chronic %}是{% else %}否{% endif %}</div>
                </div>
                <div class="info-row">
                    <div class="info-label">创建时间：</div>
                    <div class="info-value">{{ recipe.created_at|date:"Y-m-d H:i" }}</div>
                </div>
                <div class="info-row">
                    <div class="info-label">食谱描述：</div>
                    <div class="info-value">{{ recipe.description|default:'无' }}</div>
                </div>
            </div>

            <!-- 食材列表 -->
            <div class="detail-card">
                <div class="section-title">
                    <i class="fa fa-list"></i> 食材列表
                    <a href="{% url 'myadmin_recipes_ingredient_add' recipe.recipe_id %}" class="btn btn-xs btn-primary">
                        <i class="fa fa-plus"></i> 添加食材
                    </a>
                </div>
                <div class="table-box">
                    <table class="table table-bordered table-striped dataTable">
                        <thead>
                            <tr>
                                <th>序号</th>
                                <th>食材名称</th>
                                <th>数量</th>
                                <th>单位</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for ingredient in ingredients %}
                            <tr>
                                <td>{{ forloop.counter }}</td>
                                <td>{{ ingredient.food.food_name }}</td>
                                <td>{{ ingredient.quantity }}</td>
                                <td>{{ ingredient.unit }}</td>
                                <td>
                                    <a href="{% url 'myadmin_recipes_ingredient_edit' ingredient.id %}" class="btn btn-xs btn-primary">编辑</a>
                                    <a onclick="doDel('{% url 'myadmin_recipes_ingredient_delete' ingredient.id %}')" class="btn btn-xs btn-danger">删除</a>
                                </td>
                            </tr>
                            {% empty %}
                            <tr><td colspan="5">暂无食材数据</td></tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 操作按钮 -->
            <div class="btn-group">
                <a href="{% url 'myadmin_recipes_edit' recipe.recipe_id %}" class="btn btn-primary">
                    <i class="fa fa-edit"></i> 编辑食谱
                </a>
                <button type="button" class="btn btn-default" onclick="window.history.back();">
                    <i class="fa fa-arrow-left"></i> 返回列表
                </button>
            </div>
        </div>
    </div>
</section>
<script>
    function doDel(url) {
        if (confirm("确定删除该食材吗？")) {
            window.location.href = url;
        }
    }
</script>
{% endblock %}